package com.gopay.webtest.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.gopay.webtest.controller.base.BaseController;
import com.gopay.webtest.handler.STSignHandler;
import com.gopay.webtest.vo.SettlementTodayQueryVO;
import com.gopay.webtest.xml.XmlDao;

/**
 * 网关T+1商户可今日结算额度查询
 * @author ZhangYu3
 * @date 2016年8月13日15:53:04
 */
@Controller
@RequestMapping("/SettlementToday")
public class SettlementTodayController extends BaseController {
	@Resource(name="xmlDao")
	private XmlDao xmlDao;
	
	@Resource(name="stSignHandler")
	private STSignHandler stSignHandler;
	/**
	 * 查询T+1可今日结算额度入口
	 * @return
	 */
    @RequestMapping("/settlementTodayQuery")
    public ModelAndView toSettleQuery() {
//        StopWatch sw  = new StopWatch();
//        sw.start();
        ModelAndView mv = new ModelAndView();
        try {

            Map<String, String> map = xmlDao.readData4Map("settlementtoday_balance_query", "query");

            mv = new ModelAndView("gopay.webtest.settlementtoday.query");
            mv.addObject("config", map);
        } catch (Exception e) {
            logger.error("跳转到查询页面", e);
        }
//        sw.stop();
//        log.info("打开网关支付默认页面，耗时:"+sw.getTime());
        return mv;
    } 
 
    /**
     * 查询额度方法
     * @return
     */
    @RequestMapping("/balanceQuery")
    public ModelAndView balanceQuery(@ModelAttribute SettlementTodayQueryVO stQueryVO) {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("gopay.webtest.settlementtoday.doQuery");
        try {
            // 签名
        	stSignHandler.sign(stQueryVO.getTranCode()+"_"+stQueryVO.getVersion(), "signType", "signValue", stQueryVO, getRequest());
            mv.addObject("stQueryVO", stQueryVO);
        } catch (Exception e) {
            logger.error("执行查询", e);
        }
        
        return mv;
    
    }
}
